package com.exam.schedule;

import cn.hutool.json.JSONUtil;
import com.exam.common.Utils.EmailUtils2;
import com.exam.pojo.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.mail.EmailException;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Description Rabbitmq异步通知
 * @Date 2023/2/23
 * @Author ChengKe
 */

@Slf4j
@Component
public class UserApprovalAdvice {

    @Autowired
    private EmailUtils2 email;

    @RabbitListener(queues = "simple.queue")
    public void listenUserApproval(String msg) throws EmailException {
        log.info("监听到的消息为 = {}",msg);
        User user = JSONUtil.toBean(msg, User.class);
        String title = "审核通过";
        String content = "你好，你的资料已经审核通过赶快去报名吧";
        email.sendMsg(user.getUserName(),title,content);
    }
}
